home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 3006 / 3006.xpi / components / dhMP3TunesLockerProcessor.js < prev    next >
Text File  |  2010-01-15  |  6KB  |  167 lines

  1. /******************************************************************************
  2.  *            Copyright (c) 2006-2009 Michel Gutierrez. All Rights Reserved.
  3.  ******************************************************************************/
  4.  
  5. /**
  6.  * Constants.
  7.  */
  8.  
  9. const NS_MTLPROC_CID = Components.ID("{021d8a4d-5978-4632-b69a-9351bc827f01}");
  10. const NS_MTLPROC_PROG_ID = "@downloadhelper.net/mp3tunes-locker-processor;1";
  11. const DHNS = "http://downloadhelper.net/1.0#";
  12.  
  13. var Util=null;
  14.  
  15. /**
  16. * Object constructor
  17. */
  18. function MTLProc() {
  19.     try {
  20.         //dump("[MTLProc] constructor\n");
  21.         if(!Util.priorTo19()) {
  22.             this.helper=new MTProcHelper(false);
  23.             this.core=Components.classes["@downloadhelper.net/core;1"].
  24.                 getService(Components.interfaces.dhICore);
  25.             this.core.registerProcessor(this);
  26.         }
  27.     } catch(e) {
  28.         dump("[MTLProc] !!! constructor: "+e+"\n");
  29.     }
  30. }
  31.  
  32. MTLProc.prototype = {
  33.     get name() { return "mp3tunes-locker"; },
  34.     get provider() { return "MP3Tunes"; },
  35.     get title() { return Util.getText("mp3tunes.locker-processor.title"); },
  36.     get description() { return Util.getText("mp3tunes.locker-processor.description"); },
  37.     get enabled() { return this.helper.enabled; },
  38. }
  39.  
  40. MTLProc.prototype.canHandle=function(desc) {
  41.     //dump("[MTLProc] canHandle()\n");
  42.     return this.helper.canHandle(desc);
  43. }
  44.  
  45. MTLProc.prototype.requireDownload=function(desc) {
  46.     //dump("[MTLProc] requireDownload()\n");
  47.     return this.helper.requireDownload(desc);
  48. }
  49.     
  50. MTLProc.prototype.preDownload=function(desc) {
  51.     //dump("[MTLProc] preDownload()\n");
  52.     return this.helper.preDownload(desc,false,false);
  53. }
  54.  
  55. MTLProc.prototype.handle=function(desc) {
  56.     //dump("[MTLProc] handle()\n");
  57.     this.helper.handle(desc,false);
  58. }
  59.  
  60. MTLProc.prototype.QueryInterface = function(iid) {
  61.     //dump("[MTLProc] QueryInterface("+iid+")\n");
  62.     if(
  63.         iid.equals(Components.interfaces.dhIProcessor) ||
  64.         iid.equals(Components.interfaces.nsISupports)
  65.     ) {
  66.         return this;
  67.     }
  68.     throw Components.results.NS_ERROR_NO_INTERFACE;
  69. }
  70.  
  71. var vMTLProcModule = {
  72.     firstTime: true,
  73.     
  74.     /*
  75.      * RegisterSelf is called at registration time (component installation
  76.      * or the only-until-release startup autoregistration) and is responsible
  77.      * for notifying the component manager of all components implemented in
  78.      * this module.  The fileSpec, location and type parameters are mostly
  79.      * opaque, and should be passed on to the registerComponent call
  80.      * unmolested.
  81.      */
  82.     registerSelf: function (compMgr, fileSpec, location, type) {
  83.  
  84.         if (this.firstTime) {
  85.             this.firstTime = false;
  86.             throw Components.results.NS_ERROR_FACTORY_REGISTER_AGAIN;
  87.         }
  88.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  89.         compMgr.registerFactoryLocation(NS_MTLPROC_CID,
  90.                                         "MTLProc",
  91.                                         NS_MTLPROC_PROG_ID, 
  92.                                         fileSpec,
  93.                                         location,
  94.                                         type);
  95.     },
  96.  
  97.     unregisterSelf: function(compMgr, fileSpec, location) {
  98.         compMgr = compMgr.QueryInterface(Components.interfaces.nsIComponentRegistrar);
  99.         compMgr.unregisterFactoryLocation(NS_DH_MTLPROC_CID, fileSpec);
  100.     },
  101.  
  102.     /*
  103.      * The GetClassObject method is responsible for producing Factory and
  104.      * SingletonFactory objects (the latter are specialized for services).
  105.      */
  106.     getClassObject: function (compMgr, cid, iid) {
  107.         if (!cid.equals(NS_MTLPROC_CID)) {
  108.             throw Components.results.NS_ERROR_NO_INTERFACE;
  109.         }
  110.  
  111.         if (!iid.equals(Components.interfaces.nsIFactory)) {
  112.             throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
  113.         }
  114.  
  115.         return this.vMTLProcFactory;
  116.     },
  117.  
  118.     /* factory object */
  119.     vMTLProcFactory: {
  120.         /*
  121.          * Construct an instance of the interface specified by iid, possibly
  122.          * aggregating it with the provided outer.  (If you don't know what
  123.          * aggregation is all about, you don't need to.  It reduces even the
  124.          * mightiest of XPCOM warriors to snivelling cowards.)
  125.          */
  126.         createInstance: function (outer, iid) {
  127.             if (outer != null) {
  128.                 throw Components.results.NS_ERROR_NO_AGGREGATION;
  129.             }
  130.     
  131.             if(Util==null) {
  132.                 Util=Components.classes["@downloadhelper.net/util-service;1"]
  133.                     .getService(Components.interfaces.dhIUtilService);
  134.                 try {
  135.                     var jsLoader=Components.classes["@mozilla.org/moz/jssubscript-loader;1"]
  136.                         .getService(Components.interfaces.mozIJSSubScriptLoader);
  137.                     jsLoader.loadSubScript("chrome://dwhelper/content/mp3tunes/mp3tunes-proc-helper.js");
  138.                 } catch(e) {
  139.                     dump("!!! [dhQuickDownloadProcessor] createInstance: "+e+"\n");
  140.                 }
  141.             }
  142.  
  143.             return new MTLProc().QueryInterface(iid);
  144.         }
  145.     },
  146.  
  147.     /*
  148.      * The canUnload method signals that the component is about to be unloaded.
  149.      * C++ components can return false to indicate that they don't wish to be
  150.      * unloaded, but the return value from JS components' canUnload is ignored:
  151.      * mark-and-sweep will keep everything around until it's no longer in use,
  152.      * making unconditional ``unload'' safe.
  153.      *
  154.      * You still need to provide a (likely useless) canUnload method, though:
  155.      * it's part of the nsIModule interface contract, and the JS loader _will_
  156.      * call it.
  157.      */
  158.     canUnload: function(compMgr) {
  159.         return true;
  160.     }
  161. };
  162.  
  163. function NSGetModule(compMgr, fileSpec) {
  164.     return vMTLProcModule;
  165. }
  166.  
  167.